package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.OpportunityUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.apache.ibatis.annotations.Param;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/30 14:20
 * @since v1.0
 */
public interface OpportunityUserModel extends IModel<OpportunityUserEntity> {

    /**
     * 新建机会关联更新协同团队
     *
     * @param userEntity    员工实体
     * @param opportunityId 机会id
     * @param isMain        是否主负责人
     * @author long.rao
     * @date 2019-02-01 15:42
     * @throws XbbException XbbException
     */
    void opportunityUserInsert(UserEntity userEntity, Long opportunityId, int isMain) throws XbbException;

    /**
     * 批量插入
     *
     * @param opportunityUserEntityList 团队
     * @throws XbbException 异常
     */
    void insertBatch(List<OpportunityUserEntity> opportunityUserEntityList, boolean isImport) throws XbbException;

    /**
     * Description: 获取销售机会负责人/协同人的id
     * @param corpid 公司id
     * @param opportunityId  销售机会id
     * @param isMain 是否为负责人 1 负责人 0 协同人 null负责人合协同人
     * @return java.util.List<java.lang.String> 销售机会负责人/协同人id
     * @author 魏荣杰
     * @date 2018/8/2 15:03
     * @since v3.26
     * Modified by:
     */
    List<String> getOpportunityUserIdList(String corpid, Long opportunityId, Integer isMain);
    /**
     * Description: 获取销售机会负责人/协同人的id
     * @param corpid 公司id
     * @param opportunityId  销售机会id
     * @param isMain 是否为负责人 1 负责人 0 协同人 null负责人合协同人
     * @return java.util.List<java.lang.String> 销售机会负责人/协同人id
     * @author 吴峰
     * @date 2021-07-26 17:29 
     * @since v3.26
     * Modified by:
     */
    List<OpportunityUserEntity> getOpportunityUserList(String corpid, Long opportunityId, Integer isMain);

    OpportunityUserEntity getByKey(Long dataId, String corpid);

    void save(OpportunityUserEntity opportunityUserEntity) throws XbbException;

    /**
     * 批量解散团队依据客户id
     * @param corpid
     * @param customerIdIn
     */
    void disbandedTeamByCustomerId(String corpid, List<Long> customerIdIn) throws XbbException;

    /**
     * 删除机会团队成员
     * @param opportunityUser
     */
    void delete(OpportunityUserEntity opportunityUser) throws XbbException;

    /**
     * 查询协同团队基础列表
     * @param map 参数
     * @return 团队
     */
    List<UserTeamEntity> findBaseEntitys(@Param("param") Map<String,Object> map);
    @Override
    List<OpportunityUserEntity> findEntitys(@Param("param") Map<String,Object> map);

    /**
     * 批量删除
     * @param opportunityIdIn 销售机会id
     * @param corpid 公司id
     * @return
     */
    Integer deleteBatchByOpportunityIdIn(List<Long> opportunityIdIn, String corpid) throws XbbException;

    /**
     * 批量剔除团队
     * @param corpid
     * @param removeIdList 客户团队表idList
     */
    Map<Long, String> batchDeleteById(String corpid, List<Long> removeIdList) throws XbbException;

    /**
     * 获取协同团队的业务数据
     * @param corpid 公司id
     * @param isMain 负责或协同
     * @param userId 用户id
     * @return List<Long>
     * @author long.rao
     * @date 2019-03-27 21:04
     */
    List<Long> getDataIdList(String corpid, Integer isMain, List<String> userId);

    /**
     * 根据corpid,userId,opportunityId获取销售机会团队记录
     * @param corpid 公司id
     * @param userId 员工userId
     * @param opportunityId 销售机会id
     * @return 销售机会团队记录
     */
    OpportunityUserEntity getByUserIdOpportunityId(String corpid, String userId, Integer opportunityId);

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> teamEntityList, Integer isMain, Integer del, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    void deleteBatchUser(List<OpportunityUserEntity> opportunityUserEntityList, String corpid, Integer del) throws XbbException;

    void updateBatchCustomerId(List<OpportunityUserEntity> opportunityUserEntityList, String corpid) throws XbbException;

    /**
     * 批量更新
     * @author 吴峰
     * @date 2021-07-26 17:41
     * @param list
     * @param corpid
     * @return java.lang.Integer
     * @throws XbbException 业务异常
    */
    Integer updateBatch(List<OpportunityUserEntity> list, String corpid) throws XbbException;

    /**
     * 编辑团队成员标签
     *
     * @param opportunityUserEntity
     */
    void editLabel(OpportunityUserEntity opportunityUserEntity) throws XbbException;

    /**
     * 更新协同人可编辑权限
     *
     * @param opportunityUserEntity
     */
    void updateEditFormPer(OpportunityUserEntity opportunityUserEntity) throws XbbException;

    /**
     * 更新团队协同人信息和协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param updateUserToCoTeamList
     * @param coopUser
     * @param needThrow
     */
    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserToCoTeamList, Integer coopUser, boolean needThrow) throws XbbException;

    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, boolean needThrow, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;
}
